home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WTREEVW.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  15.1 KB  |  469 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WTreeView -- Wrapper for the Windows 95 TreeView control.
  14.  *
  15.  *
  16.  *   Events:
  17.  *
  18.  *       BeginLabelEdit --
  19.  *
  20.  *       Click -- When an item is clicked.
  21.  *
  22.  *       Collapse -- When an item has collapsed.
  23.  *
  24.  *       DoubleClick -- When an item is double-clicked.
  25.  *
  26.  *       EndLabelEdit --
  27.  *
  28.  *       Expand -- When an item has expanded.
  29.  *
  30.  *       NeedItemText --
  31.  *
  32.  *       RightClick --
  33.  *
  34.  *       Select --
  35.  *
  36.  *       SelectChanging --
  37.  *
  38.  *************************************************************************/
  39.  
  40. #ifndef _WTREEVW_HPP_INCLUDED
  41. #define _WTREEVW_HPP_INCLUDED
  42.  
  43. #ifndef _WNO_PRAGMA_PUSH
  44. #pragma pack(push,8);
  45. #pragma enum int;
  46. #endif
  47.  
  48. #ifndef _WCONTROL_HPP_INCLUDED
  49. #  include "wcontrol.hpp"
  50. #endif
  51. #ifndef _WLLIST_HPP_INCLUDED
  52. #  include "wllist.hpp"
  53. #endif
  54. #ifndef _WIMGLIST_HPP_INCLUDED
  55. #  include "wimglist.hpp"
  56. #endif
  57.  
  58.  
  59. class WTreeView;
  60. class WTextBox;
  61.  
  62. enum WTreeViewItemHandle { NULLHTVITEM  = 0,  LASTHTVITEM = LAST_32BIT };
  63.  
  64. typedef WBool WCMDEF (WObject::*WTreeViewCallback)( WTreeView * treeView, WTreeViewItemHandle item, void * userData );
  65.  
  66.  
  67. enum WTVImageListType {
  68.     WTVINormal, 
  69.     WTVIState
  70. };
  71.  
  72. enum WTreeViewCChildren {
  73.     WTVC_NO_CHILDREN = 0,
  74.     WTVC_HAS_CHILDREN,
  75.     WTVC_FIELD_UNUSED
  76. };
  77.  
  78. // flags
  79.  
  80. #define WTVIfText               0x0001
  81. #define WTVIfImage              0x0002
  82. #define WTVIfParam              0x0004
  83. #define WTVIfState              0x0008
  84. #define WTVIfHandle             0x0010
  85. #define WTVIfSelectedImage      0x0020
  86. #define WTVIfChildren           0x0040
  87.  
  88. // TreeView item state masks
  89.  
  90. #define WTVIsFocused            0x0001
  91. #define WTVIsSelected           0x0002
  92. #define WTVIsCut                0x0004
  93. #define WTVIsDropHilited        0x0008
  94. #define WTVIsBold               0x0010
  95. #define WTVIsExpanded           0x0020
  96. #define WTVIsExpandedOnce       0x0040
  97. #define WTVIsOverlayMask        0x0F00
  98. #define WTVIsStateImageMask     0xF000
  99. #define WTVIsUserMask           0xF000
  100.  
  101. struct WTreeViewEventData : public WEventData {
  102.     WTreeViewItemHandle         item;
  103.     WTreeViewItemHandle         oldItem;
  104. };
  105.  
  106. struct WTreeViewDispEventData : public WEventData {
  107.     WUInt                mask;
  108.     WTreeViewItemHandle  itemHandle;
  109.     WUInt                state;
  110.     WUInt                stateMask;
  111.     const WChar *        itemText;
  112.     WInt                 textMax;
  113.     WInt                 imageIndex;
  114.     WInt                 selectedImageIndex;
  115.     WInt                 children;
  116.     void *               userData;
  117. };
  118.  
  119. //
  120. // TreeView styles
  121. //
  122.  
  123. #define WTVSDefault           ((WStyle)0x50000007L) // WS_VISIBLE|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|WS_CHILD
  124. #define WTVSHasButtons        ((WStyle)0x00000001L) // TVS_HASBUTTONS
  125. #define WTVSHasLines          ((WStyle)0x00000002L) // TVS_HASLINES
  126. #define WTVSLinesAtRoot       ((WStyle)0x00000004L) // TVS_LINESATROOT
  127. #define WTVSEditLabels        ((WStyle)0x00000008L) // TVS_EDITLABELS
  128. #define WTVSDisabledDragDrop  ((WStyle)0x00000010L) // TVS_DISABLEDRAGDROP
  129. #define WTVSShowSelAlways     ((WStyle)0x00000020L) // TVS_SHOWSELALWAYS
  130.  
  131. #define WTVFocusedState      0x0001
  132. #define WTVSelectedState     0x0002
  133. #define WTVCutState          0x0004
  134. #define WTVDropHilitedState  0x0008
  135. #define WTVBoldState         0x0010
  136. #define WTVExpandedState     0x0020
  137. #define WTVExpandedOnceState 0x0040
  138.  
  139. #define WTVInsertRoot    ((WTreeViewItemHandle)0xFFFF0000L)
  140. #define WTVInsertFirst   ((WTreeViewItemHandle)0xFFFF0001L)
  141. #define WTVInsertLast    ((WTreeViewItemHandle)0xFFFF0002L)
  142. #define WTVInsertSort    ((WTreeViewItemHandle)0xFFFF0003L)
  143.  
  144. #define WTVDeleteRoot    WTVInsertRoot
  145.  
  146. #define WTVNIRoot               0x0000 
  147. #define WTVNINext               0x0001
  148. #define WTVNIPrevious           0x0002
  149. #define WTVNIParent             0x0003
  150. #define WTVNIChild              0x0004
  151. #define WTVNIFirstVisible       0x0005
  152. #define WTVNINextVisible        0x0006
  153. #define WTVNIPreviousVisible    0x0007
  154. #define WTVNIDropHilite         0x0008
  155. #define WTVNICaret              0x0009
  156. #define WTVNISelected           WTVNICaret
  157.  
  158. class WCMCLASS WTreeView : public WControl {
  159.     WDeclareSubclass( WTreeView, WControl );
  160.  
  161.     public:
  162.  
  163.         /**********************************************************
  164.          * Constructors and Destructors
  165.          *********************************************************/
  166.  
  167.         WTreeView();
  168.     
  169.         ~WTreeView();
  170.  
  171.         /**********************************************************
  172.          * Properties
  173.          *********************************************************/
  174.  
  175.         // Count -- Gets the number of items in the treeview.
  176.  
  177.         WULong GetCount() const;
  178.  
  179.         // ImageList
  180.         //
  181.         //     Get or set one of the imagelists used by the treeview.
  182.         //     All imagelists are shared, so it is up to the user
  183.         //     to destroy the imagelist after destroying the treeview.
  184.  
  185.         WImageList * GetImageList( WTVImageListType type=WTVINormal ) const;
  186.         WBool        SetImageList( WImageList * imageList,
  187.                                    WTVImageListType type=WTVINormal );
  188.  
  189.         // Selected
  190.         //
  191.         //     The selected item.
  192.  
  193.         WBool SetSelectedItem( WTreeViewItemHandle item );
  194.         WTreeViewItemHandle GetSelectedItem() const;
  195.  
  196.         /**********************************************************
  197.          * Methods
  198.          *********************************************************/
  199.  
  200.         // Add
  201.         //
  202.         //     Add a new item.  The label can be NULL.  The imageIndex
  203.         //     refers to the index into the imagelist.  The itemData is
  204.         //     per-item userdata.  If parent is NULL, item is added
  205.         //     at the root level.  If insertAfter is NULL, item is
  206.         //     added at end of sibling group -- other valid choices
  207.         //     are WTVInsertFirst, WTVInsertLast, WTVInsertSort.
  208.         //     Returns NULL if error occurs.
  209.  
  210.         WTreeViewItemHandle Add( const WChar *label,
  211.                                  WTreeViewItemHandle parent=NULLHTVITEM,
  212.                                  WLong imageIndex=0,
  213.                                  WLong selectedImageIndex=-1,
  214.                                  WShort stateImageIndex=0,
  215.                                  WTreeViewItemHandle insertAfter=NULLHTVITEM,
  216.                                  void *itemData=NULL,
  217.                                  WTreeViewCChildren cChildren=WTVC_FIELD_UNUSED );
  218.  
  219.         // CreateDragImage
  220.         //
  221.         //     Returns an imagelist that can be used for drawing purposes
  222.         //     during a drag operation.  Caller must delete the image
  223.         //     list when done.  
  224.  
  225.         WImageList CreateDragImage( WTreeViewItemHandle item ) const;
  226.  
  227.         // DeleteAll
  228.         //
  229.         //     Clear all the items in the treeview.
  230.  
  231.         WBool DeleteAll();
  232.  
  233.         // Delete
  234.         //
  235.         //     Delete an item in the treeview.  All descendents are
  236.         //     also deleted... If NULL is passed, nothing is deleted.
  237.         //     You can pass in WTVDeleteRoot to delete everything.
  238.  
  239.         WBool Delete( WTreeViewItemHandle item );
  240.  
  241.         // Retrieve
  242.         //
  243.         //     Retrieves an item by position or by state.  The startAt value
  244.         //     is where the search should start.
  245.         //
  246.         //     Returns the item, or NULL if not found.
  247.  
  248.         WTreeViewItemHandle Retrieve( const WPoint & pt ) const;
  249.         WTreeViewItemHandle Retrieve( WTreeViewItemHandle startAt=NULLHTVITEM,
  250.                                       WULong flags=WTVNISelected ) const;
  251.  
  252.         // Collapse
  253.         //
  254.         //     Collapse an item.
  255.  
  256.         WBool Collapse( WTreeViewItemHandle item, WBool deleteItems=FALSE );
  257.  
  258.         // Expand
  259.         //
  260.         //     Expand an item.
  261.  
  262.         WBool Expand( WTreeViewItemHandle item );
  263.  
  264.         // Toggle
  265.         //
  266.         //     Expand/collapse an item.
  267.  
  268.         WBool Toggle( WTreeViewItemHandle item );
  269.  
  270.         // EditLabel
  271.         //
  272.         //     Invoke label editing for an item.
  273.  
  274.         WWindowHandle EditLabel( WTreeViewItemHandle itemHandle);
  275.         
  276.         // EnsureIsFirstVisible
  277.         //
  278.         //     Ensures that an item is the first visible item
  279.         //     OF ITS INDENTATION LEVEL.
  280.  
  281.         WBool EnsureIsFirstVisible( WTreeViewItemHandle item );
  282.                 
  283.         // EnsureIsVisible
  284.         //
  285.         //     Ensure that an item is visible.
  286.  
  287.         WBool EnsureIsVisible( WTreeViewItemHandle item );
  288.  
  289.         /**********************************************************
  290.          * Item Methods
  291.          *********************************************************/
  292.  
  293.         // CollapseAll
  294.  
  295.         WBool CollapseAll( WTreeViewItemHandle item=NULLHTVITEM );
  296.  
  297.         // Enumerate
  298.  
  299.         WBool Enumerate( WObject * client, WTreeViewCallback callback,
  300.                          void * userData=NULL );
  301.  
  302.         // EnumerateChildren
  303.  
  304.         WBool EnumerateChildren( WTreeViewItemHandle item, WObject * client,
  305.                                  WTreeViewCallback callback,
  306.                                  void * userData=NULL );
  307.  
  308.         // ExpandAll
  309.  
  310.         WBool ExpandAll( WTreeViewItemHandle item=NULLHTVITEM,
  311.                          WBool expandSelf=TRUE );
  312.  
  313.         /**********************************************************
  314.          * Item Properties
  315.          *********************************************************/
  316.  
  317.         // Expanded
  318.  
  319.         WBool SetExpanded( WTreeViewItemHandle item, WBool expanded );
  320.         WBool GetExpanded( WTreeViewItemHandle item ) const;
  321.  
  322.         // ImageIndex
  323.  
  324.         WBool SetImageIndex( WTreeViewItemHandle item, WLong index );
  325.         WLong GetImageIndex( WTreeViewItemHandle item ) const;
  326.  
  327.         // Selected
  328.  
  329.         WBool SetSelected( WTreeViewItemHandle item, WBool selected=TRUE,
  330.                            WBool singleSelection=TRUE );
  331.         WBool GetSelected( WTreeViewItemHandle item ) const;
  332.  
  333.         // SelectedImageIndex
  334.  
  335.         WBool SetSelectedImageIndex( WTreeViewItemHandle item, WLong index );
  336.         WLong GetSelectedImageIndex( WTreeViewItemHandle item ) const;
  337.  
  338.         // StateImageIndex
  339.  
  340.         WBool SetStateImageIndex( WTreeViewItemHandle item, WShort index );
  341.         WShort GetStateImageIndex( WTreeViewItemHandle item ) const;
  342.  
  343.         // Rectangle
  344.         //
  345.         //     Get/set the rectangle where the control is placed
  346.         //     If an handle of Item is supplied, then the rectangle applies
  347.         //     to the position
  348.  
  349.         WRect GetRectangle( WTreeViewItemHandle item, WBool type=TRUE );
  350.  
  351.         // Text
  352.         //
  353.         //     Get or set the caption of an item.
  354.  
  355.         WString GetText( WTreeViewItemHandle item ) const;
  356.         WBool   GetText( WTreeViewItemHandle item, WString *str ) const;
  357.         WBool   SetText( WTreeViewItemHandle item, const WString & text );
  358.  
  359.         // UserData
  360.         //
  361.         //     Set/Get per-item data.
  362.  
  363.         WBool  SetUserData( WTreeViewItemHandle item, void *itemUserData );
  364.         void * GetUserData( WTreeViewItemHandle item ) const;
  365.  
  366.         // State
  367.         //
  368.         //     Set/Get treeview item state information
  369.  
  370.         WUInt GetState( WTreeViewItemHandle item,
  371.                         WUInt stateMask=WTVIsSelected );
  372.         WBool SetState( WTreeViewItemHandle item, WUInt state,
  373.                         WUInt stateMask=WTVIsSelected );
  374.  
  375.         /**********************************************************
  376.          * Event Handlers
  377.          *********************************************************/
  378.  
  379.         WBool DragEnterHandler( WTreeView *, WDragEventData * );
  380.  
  381.         WBool DragOverHandler( WTreeView *, WDragEventData * );
  382.  
  383.         WBool DragLeaveHandler( WTreeView *, WDragEventData * );
  384.  
  385.         WBool ContextMenuEventHandler( WTreeView *, WContextMenuEventData * );
  386.  
  387.         WBool RightClickEventHandler( WTreeView *, WTreeViewEventData * );
  388.  
  389.     protected:
  390.  
  391.         WBool DestroyEventHandler( WTreeView *, WEventData * );
  392.  
  393.         /**********************************************************
  394.          * Overrides
  395.          *********************************************************/
  396.  
  397.     public:
  398.  
  399.         virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
  400.  
  401.         virtual WBool SetParent( const WWindow * parent );
  402.  
  403.         virtual WBool WantsDragMessage( WULong whichButton ) const;
  404.         virtual WBool FillDragEventData( WDragEventData & event ) const;
  405.  
  406.         virtual WBool SetText( const WString & str );
  407.  
  408.         virtual WString GetText() const;
  409.  
  410.         virtual WRect GetRectangle( WBool absolute=FALSE ) const;
  411.  
  412.         virtual WBool SetUserData( void * userData );
  413.  
  414.         virtual void * GetUserData() const;
  415.  
  416.         virtual const WChar * InitializeClass();
  417.  
  418.         virtual WStyle GetDefaultStyle() const;
  419.  
  420.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  421.                                    void * data=NULL );
  422.  
  423.         virtual WBool Destroy();
  424.  
  425.     protected:
  426.  
  427.         virtual WBool ProcessNotify( WUInt id, WNotify code,
  428.                                      WNotifyInfo info, WLong & returns );
  429.     
  430.         /**********************************************************
  431.          * Others
  432.          *********************************************************/
  433.  
  434.     private:
  435.  
  436.         WBool Expand( WTreeView * tv, WTreeViewItemHandle item,
  437.                       void * userData );
  438.  
  439.         WBool Collapse( WTreeView *tv, WTreeViewItemHandle item,
  440.                         void *userData );
  441.  
  442.         WBool StoreChildren( WTreeView *tv, WTreeViewItemHandle item,
  443.                              void *userData );
  444.  
  445.         WBool RestoreChildren( WTreeView *tv, WTreeViewItemHandle item,
  446.                                void *userData );
  447.  
  448.         /**********************************************************
  449.          * Data Members
  450.          *********************************************************/
  451.  
  452.     private:
  453.  
  454.         WImageList *            _normalImages;
  455.         WImageList *            _stateImages;
  456.         WULong                  _itemBufferLength;
  457.         WBool                   _inRightClick;
  458.         WTreeViewItemHandle     _storedHandle;
  459.         WTreeViewItemHandle     _dragSelectedHandle;
  460.         WTextBox *              _editor;
  461. };
  462.  
  463. #ifndef _WNO_PRAGMA_PUSH
  464. #pragma enum pop;
  465. #pragma pack(pop);
  466. #endif
  467.  
  468. #endif // _WTREEVW_HPP_INCLUDED
  469.